import { Button, Label } from 'cc';
import Biz from '../biz';
import { EventName } from '../consts/events';
import Utils from '../utils';
import { UiBasic } from './basic';

// 游戏结束结算界面
export class UiSettlement extends UiBasic {
    private maxScore: number = 0;
    private lbMax: Label;
    private lbCur: Label;

    protected onLoad(): void {
        const restartButton = this.node.getChildByPath('restart');
        restartButton.on(Button.EventType.CLICK, this.restart, this);

        const lbMax = this.node.getChildByPath('max');
        this.lbMax = lbMax.getComponent(Label);
        const lbCur = this.node.getChildByPath('cur');
        this.lbCur = lbCur.getComponent(Label);
        this.node.setPosition(0, 0);
        this.hide();
    }
    public setScore() {
        const score = Biz.score.getScore();
        if (score > this.maxScore) {
            this.maxScore = score;
        }
        this.lbMax.string = `${this.maxScore}`;
        this.lbCur.string = `${score}`;
    }
    private restart() {
        Utils.events.emit(EventName.StartGame);
    }
}
